﻿using System;
using System.IO;

namespace SharpOSCAR.Base
{
    /// <summary>
    /// Represents a U32 (unsigned 16-bit integer) data type
    /// </summary>
    public class U32 : ProtocolData
    {
        private uint _Value;
        /// <summary>
        /// Value
        /// </summary>
        public uint Value
        {
            get { return _Value; }
            set { _Value = value; }
        }

        /// <summary>
        /// Initializes the U32 with the specified value
        /// </summary>
        /// <param name="value">Value</param>
        public U32(uint value)
        {
            _Value = value;
        }

        /// <summary>
        /// Converts the U32 into a byte array
        /// </summary>
        /// <returns>Returns a byte array representing the U32</returns>
        public override byte[] ToByteArray()
        {
            byte[] values = BitConverter.GetBytes(_Value);
            if (BitConverter.IsLittleEndian)
            {
                byte tempVal3 = values[3];
                byte tempVal2 = values[2];
                values[3] = values[0];
                values[2] = values[1];
                values[1] = tempVal2;
                values[0] = tempVal3;
            }
            return values;
        }
    }
}
